package net.awpspace.walkman.utils;

import java.io.IOException;
import java.util.Hashtable;

import javax.microedition.lcdui.Image;

/**
 * Utilities related to image processing
 * 
 * @author Diep AwpSpace
 * 
 */
public class ImageUtils {

	public static final String SHEET_LIBRARY = "/sheet_library.png";
	public static final String SHEET_NOWPLAYING = "/sheet_nowplaying.png";
	public static final String SHEET_PIANO = "/sheet_piano.png";

	public static final String CTRL_PREV = "/ctrl_prev.png";
	public static final String CTRL_PLAY = "/ctrl_play.png";
	public static final String CTRL_NEXT = "/ctrl_next.png";

	public static final String IMG_HEADER = "/np_header.png";
	public static final String IMG_ALBUM = "/album.png";
	public static final String IMG_ARTIST = "/artist.png";
	public static final String IMG_TRACK = "/track.png";
	public static final String IMG_BACK = "/back.png";
	public static final String IMG_ART = "/art.png";

	private static Hashtable images;

	/**
	 * get assest
	 * 
	 * @param index
	 * @return image
	 */
	public static Image getImage(String key) {
		if (images == null) {
			initAssest();
		}
		return (Image) images.get(key);
	}

	/**
	 * Resource initialization
	 */
	private static void initAssest() {
		images = new Hashtable();
		try {
			images.put(SHEET_LIBRARY, Image.createImage(SHEET_LIBRARY));
			images.put(SHEET_NOWPLAYING, Image.createImage(SHEET_NOWPLAYING));
			images.put(SHEET_PIANO, Image.createImage(SHEET_PIANO));

			images.put(CTRL_PREV, Image.createImage(CTRL_PREV));
			images.put(CTRL_PLAY, Image.createImage(CTRL_PLAY));
			images.put(CTRL_NEXT, Image.createImage(CTRL_NEXT));

			images.put(IMG_HEADER, Image.createImage(IMG_HEADER));
			images.put(IMG_ALBUM, Image.createImage(IMG_ALBUM));
			images.put(IMG_ARTIST, Image.createImage(IMG_ARTIST));
			images.put(IMG_TRACK, Image.createImage(IMG_TRACK));
			images.put(IMG_BACK, Image.createImage(IMG_BACK));
			images.put(IMG_ART, Image.createImage(IMG_ART));
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
